package cn.gistone.visualeditor.business.controller;

import cn.gistone.visualeditor.business.service.VisualScreenService;
import cn.gistone.visualeditor.dto.VisualScreenDto;
import cn.gistone.visualeditor.dto.VisualScreenQueryDto;
import cn.gistone.visualeditor.entity.VisualScreen;
import cn.gistone.visualeditor.utils.AjaxResult;
import cn.gistone.visualeditor.utils.FileUploadUtils;
import cn.gistone.visualeditor.utils.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/visualScreen")
@Api(tags = "可视化数据")
public class VisualScreenController {
    @Autowired
    private VisualScreenService visualScreenService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public AjaxResult add(@RequestBody VisualScreenDto dto){
        try {
            visualScreenService.add(dto);
            return AjaxResult.ok();
        } catch (Exception e){
            return AjaxResult.fail("操作失败");
        }
    }

    @PostMapping("/update")
    @ApiOperation("修改")
    public AjaxResult update(@RequestBody VisualScreenDto dto){
        try {
            visualScreenService.update(dto);
            return AjaxResult.ok();
        } catch (Exception e){
            return AjaxResult.fail("操作失败");
        }
    }
    @PostMapping("/copy")
    @ApiOperation("复制")
    public AjaxResult copy(@RequestBody VisualScreenDto dto){
        try {
            visualScreenService.copy(dto);
            return AjaxResult.ok();
        } catch (Exception e){
            return AjaxResult.fail("操作失败");
        }
    }

    @PostMapping("/getUserScreen")
    @ApiOperation("分页获取用户屏幕列表")
    public PageResult<VisualScreen> getUserScreen(@RequestBody VisualScreenQueryDto dto){
        return visualScreenService.getByUserId(dto);
    }

    @GetMapping("/deleteScreenById")
    @ApiOperation("根据id删除屏幕")
    public AjaxResult deleteScreenById(String id){
        try {
            visualScreenService.deleteById(id);
            return AjaxResult.ok();
        } catch (Exception e){
            return AjaxResult.fail("操作失败");
        }
    }

}
